import 'package:app_03/views/cart.dart';
import 'package:app_03/views/cata.dart';
import 'package:app_03/views/home.dart';
import 'package:app_03/views/person.dart';
import 'package:flutter/material.dart';

main() {
  runApp(MaterialApp(home: Page0()));
}

class Page0 extends StatefulWidget {
  const Page0({super.key});

  @override
  State<StatefulWidget> createState() => _Page0State();
}

class _Page0State extends State<Page0> {
  List _pages = [HomePage(), Category(), Cart(), Person()];
  List<BottomNavigationBarItem> _bottomItems = [
    BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
    BottomNavigationBarItem(icon: Icon(Icons.category), label: '分类'),
    BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: '购物车'),
    BottomNavigationBarItem(icon: Icon(Icons.manage_accounts), label: '个人中心'),
  ];
  int _currentPageIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 应用栏
      appBar: AppBar(
        title: const Text('SCAFFOLDDD'), // 标题
        centerTitle: true, // 标题居中
        // 右侧组件
        actions: [
          IconButton(onPressed: () {}, icon: Icon(Icons.search)),
          IconButton(onPressed: () {}, icon: Icon(Icons.more_horiz)),
        ],
        // leading: IconButton( // 左侧小组件
        //   icon: Icon(Icons.arrow_back),
        //   onPressed: () {},
        // ),
      ),

      // 抽屉。若设置 appBar.leading 则无法设置抽屉
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero, // 改变抽屉部分【手机状态栏】颜色
          children: [
            UserAccountsDrawerHeader(
                currentAccountPicture: CircleAvatar(
                  backgroundImage: AssetImage('images/pic.jpg'),
                ),
                accountName: Text('Zhangsan'),
                accountEmail: Text('zhangsan@gmail.com')),
            // DrawerHeader(
            //   child: Text('header'),
            //   decoration: BoxDecoration(color: Colors.blue[200]),
            // ),
            ListTile(
              title: Text(
                '个人资料',
                style: TextStyle(
                    color: Colors.blue[300], fontWeight: FontWeight.w600),
              ),
              trailing: IconButton(
                onPressed: () {},
                icon: Icon(Icons.person),
              ),
            ),
            ListTile(
              title: Text(
                '隐私设置',
                style: TextStyle(
                    color: Colors.blue[300], fontWeight: FontWeight.w600),
              ),
              trailing: IconButton(
                onPressed: () {},
                icon: Icon(Icons.privacy_tip),
              ),
            ),
            ListTile(
              title: Text(
                '注销登录',
                style: TextStyle(
                    color: Colors.blue[300], fontWeight: FontWeight.w600),
              ),
              trailing: IconButton(
                onPressed: () {},
                icon: Icon(Icons.logout),
              ),
            ),
          ],
        ),
      ),

      // 浮动按钮，位置
      // floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
      // floatingActionButton: FloatingActionButton(
      //   onPressed: () {},
      //   child: Icon(Icons.add),
      // ),

      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed, // 当 items.length >3
        items: _bottomItems,
        currentIndex: _currentPageIndex,
        onTap: (index) {
          setState(() {
            print('current page index: ${index}');
            _currentPageIndex = index;
          });
        },
      ),

      body: _pages[_currentPageIndex],
    );
  }
}
